var placemarks = new Array();

function createPlacemark(title, name, lat, lon) {
  var placemark = ge.createPlacemark('');
  placemark.setName(title);
  ge.getFeatures().appendChild(placemark);

  // Create style map for placemark
  var normal = ge.createIcon('');
  normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
  var iconNormal = ge.createStyle('');
  iconNormal.getIconStyle().setIcon(normal);
  var highlight = ge.createIcon('');
  highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
  var iconHighlight = ge.createStyle('');
  iconHighlight.getIconStyle().setIcon(highlight);
  var styleMap = ge.createStyleMap('');
  styleMap.setNormalStyle(iconNormal);
  styleMap.setHighlightStyle(iconHighlight);
  placemark.setStyleSelector(styleMap);

  // Create point
  var point = ge.createPoint('');
  point.setLatitude(lat);
  point.setLongitude(lon);
  log('Created placemark \''+ title +'\' at:<br/>&nbsp;&nbsp;'+ lat +','+ lon);
  placemark.setGeometry(point);
  placemarks[name] = placemark;
  return placemark;
}

function createLine(lat1, lon1, lat2, lon2) {
  var lineStringPlacemark = ge.createPlacemark('');
  var lineString = ge.createLineString('');
  lineStringPlacemark.setGeometry(lineString);
  lineString.setTessellate(true);
  lineString.getCoordinates().
    pushLatLngAlt(lat1, lon1, 0);
  lineString.getCoordinates().
    pushLatLngAlt(lat2, lon2, 0);
  ge.getFeatures().appendChild(lineStringPlacemark);
}

function getPlacemark(name) {
  return placemarks[name];
}

function clearPlacemarks() {
  for (var p in placemarks) {
    ge.getFeatures().removeChild(placemarks[p]);
    log('removed: '+ p);
    delete placemarks[p];
  }
}
